//
//  ZPWelViewController.swift
//  ZPWeibo
//
//  Created by zhangpeng on 16/4/19.
//  Copyright © 2016年 zhangpeng. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class ZPWelViewController: UIViewController {

    override func loadView() {
        view = bgImageView
        
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    override func viewDidAppear(animated: Bool) {
        
        super.viewDidAppear(animated)
        
        setHeadImageViewAnimate()
    }
    
    private func setHeadImageViewAnimate(){
    
        headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            //
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        //发送通知切换控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchDefaultVcNSNotification, object: "welcome")
                })
        }
    }
    
    private func setupUI(){
    
        view.addSubview(headImageView)
        
        view.addSubview(messageLabel)
        
        headImageView.snp_makeConstraints { (make) -> Void in
           make.size.equalTo(CGSize(width: 85, height: 85))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)

        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
        
    }
    
    private lazy var bgImageView:UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    private lazy var headImageView:UIImageView = {
    
        let img = UIImageView(image: UIImage(named: "avatar_default_big"))
        
        img.layer.cornerRadius = 85 / 2
        
        img.layer.borderColor = ThemeColor.CGColor
        
        img.layer.borderWidth = 2
        img.clipsToBounds = true
        
       img.sd_setImageWithURL(NSURL(string: ZPUserAccountTools.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
        
        return img
    }()
    
    //欢迎回来
    private lazy var messageLabel:UILabel = {
    
        let lab = UILabel(textColor: UIColor.darkGrayColor(), textFont: 17)

        lab.textAlignment = .Center
        
        lab.text = "欢迎回来"
        
        lab.alpha = 0
        
        return lab
    }()

    
}
